package o;

import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import com.huawei.appgallery.packagemanager.api.bean.ManagerTask;

public class cpj implements Runnable {
    private ManagerTask ˊ;
    private Context ॱ;

    public cpj(Context context, ManagerTask managerTask) {
        this.ॱ = context.getApplicationContext();
        this.ˊ = managerTask;
    }

    public void run() {
        cnu.ˏ.ˋ("PackageManagerRunnable", " PackageManagerRunnable run pkg:" + this.ˊ.packageName + ",processType:" + this.ˊ.processType + ",flag:" + this.ˊ.flag);
        switch (this.ˊ.processType) {
            case INSTALL:
                if (ˏ()) {
                    ˋ();
                    return;
                }
                return;
            case INSTALL_EXISTING_PKG:
                ˋ();
                return;
            case UNINSTALL:
                cpf.ˋ(this.ॱ).ॱ(8, this.ˊ);
                if (this.ˊ.splitNames == null || this.ˊ.splitNames.isEmpty()) {
                    cpy.ˎ(this.ॱ, this.ˊ);
                    return;
                } else {
                    cpw.ˋ(this.ॱ, this.ˊ);
                    return;
                }
            default:
                Logger.e("PackageManagerRunnable", "unknow processType");
                return;
        }
    }

    private boolean ˏ() {
        if (this.ˊ.mode != 1 || (this.ˊ.flag & 16) == 0) {
            return true;
        }
        try {
            boolean z;
            if (this.ॱ.getPackageManager().getPackageInfo(this.ˊ.packageName, 0) != null) {
                this.ˊ.status = cnz.NOT_HANDLER;
                cnu.ˏ.ˋ("PackageManagerRunnable", "can not install because app is installed," + this.ˊ.packageName);
                if (this.ˊ.processType == cod.INSTALL) {
                    cpa.ˊ().ˋ(this.ॱ, this.ˊ);
                }
                cph.ॱ(this.ॱ).ˋ(this.ˊ.packageName, 1, cnz.NOT_HANDLER, -1000001, 5, this.ˊ.taskId, cod.INSTALL);
                z = false;
            } else {
                z = true;
            }
            return z;
        } catch (NameNotFoundException e) {
            Logger.ˎ("PackageManagerRunnable", "app not installed");
            return true;
        }
    }

    private void ˋ() {
        this.ˊ.status = cnz.INSTALLING;
        cpf.ˋ(this.ॱ).ॱ(3, this.ˊ);
        cps.ˊ(this.ॱ, this.ˊ);
    }
}
